file (STRINGS VERSION VERSION_STRINGS LIMIT_COUNT 4)

list (GET VERSION_STRINGS 0 MAJOR_VERSION)
list (GET VERSION_STRINGS 1 MINOR_VERSION)
list (GET VERSION_STRINGS 2 FIX_VERSION)
list (LENGTH VERSION_STRINGS VERSION_STRINGS_LENGTH)

if (${VERSION_STRINGS_LENGTH} LESS 4)
    set (VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${FIX_VERSION}")
else ()
    list (GET VERSION_STRINGS 3 SPEC_VERSION)
    set (VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${FIX_VERSION}.${SPEC_VERSION}")
endif ()
